package com.jtx.miaoah2.handler;

import com.jtx.miaoah2.Common.BaseResponse;
import com.jtx.miaoah2.Common.CustomException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 季台星
 * @Date 2023 07 23 14 08
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public BaseResponse exceptionHandler(Exception e){
        return BaseResponse.fail(500,e.getMessage());
    }
    @ExceptionHandler(NullPointerException.class)
    public BaseResponse nullpointExceptionHandler(NullPointerException e){
        return BaseResponse.fail(500,"空指针异常" + e.getCause());
    }

    /**
     * 自定义业务异常
     * @param e
     * @return
     */
    @ExceptionHandler(CustomException.class)
    public BaseResponse customExceptionHandler(CustomException e){
        return BaseResponse.fail(500,"业务异常" + e.getMsg());
    }
}
